(function () {

//获取页面数据
	getPageData();
	 
	 function getPageData (Filter)
	 {
	 	var Filter = Filter;

	 	$.ajax({  //获得所有品牌
	 		url: Domain+'/ec/brand/doSearchAllBrandList.do',
	 		type: 'GET'
	 	})
	 	.done(function(res) {

		 		if(!res.success){
		
			    $('.am-modal-bd').text(res.errorMessage);
					$modal.modal();
					setTimeout(function () {
						$modal.modal('close');
					},iWiating);

			  }
			  else{

			  	 renderTmp('#pinpailist', 'pinpailisttpl',res);
			  }
	 	});



	 	$.ajax({  //获得所有型号
	 		url: Domain+'/ec/machModel/doSearchAllMachModelList.do',
	 		type: 'GET'
	 	})
	 	.done(function(res) {

		 		if(!res.success){
		
			    $('.am-modal-bd').text(res.errorMessage);
					$modal.modal();
					setTimeout(function () {
						$modal.modal('close');
					},iWiating);

			  }
			  else{

			  	 renderTmp('#chexinglist', 'chexinglisttpl',res);

			  }
	 	});


	 	




	 };


  //获取层级

   if($('#provincelist').length)
   {
   	 laodAreas ({});
   }
	 
	 function laodAreas (Filter)
	 {
	 	getJson(Domain+'/common/doLoadAllArea.do', Filter, function (res) {

		  if(!res.success){
	
		    $('.am-modal-bd').text(res.errorMessage);
				$modal.modal();
				setTimeout(function () {
					$modal.modal('close');
				},iWiating);

		  }
		  else{

		  	console.log(res);

		  	for (var i = 0; i< res.data.length; i++)
		  	{
		  		$('#provincelist').append('<option value="'+res.data[i].value+'">'+res.data[i].text+'</option>');
		  	}

		  	oMenuData = res.data;

	  	 	 //createCityList(0,oMenuData);

		  }
		},function (error) {

			$('.am-modal-bd').text(language.ajaxFailed);
							$modal.modal();
						setTimeout(function () {
							$modal.modal('close');
						},iWiating);

		});
	 }

	//生成对应城市层级
	function createCityList(index,data)
	{
		$('#citylist').empty().append('<option value="" selected>市</option>');

			for (var i = 0 ; i < data[index].children.length; i++)
		  	{
		  		$('#citylist').append('<option value="'+data[index].children[i].value+'">'+data[index].children[i].text+'</option>');
		  	}

		 	createAreaList(data[index].children[0]);
	}

	//生成对应区域数据
	function createAreaList(data)
	{
		$('#arealist').empty().append('<option value="" selected>县</option>');

		for (var i = 0 ; i < data.children.length; i++)
	  	{
	  		$('#arealist').append('<option value="'+data.children[i].value+'">'+data.children[i].text+'</option>');
	  	}
	}


	//省份市级联动
	$('#provincelist').on('change',function () {

		iProvinceIndex = $(this).find('option').index($(this).find('option:selected'));
		iProvinceIndex = parseInt(iProvinceIndex)-1;

		if(iProvinceIndex==-1)
		{
			$('#citylist').empty().append('<option value="" selected>市</option>');
			$('#arealist').empty().append('<option value="" selected>县</option>');
			return;
		}

		createCityList(iProvinceIndex,oMenuData);

	});

	//市级区域联动
	$('#citylist').on('change',function () {

		iCityIndex = $(this).find('option').index($(this).find('option:selected'));
		iCityIndex = parseInt(iCityIndex)-1;

		if(iCityIndex==-1)
		{
			$('#arealist').empty().append('<option value="" selected>县</option>');
			return;
		}

		createAreaList(oMenuData[iProvinceIndex].children[iCityIndex]);

	});

	//区域查询
	$('#arealist').on('change',function () {

		iAreaIndex = $(this).find('option').index($(this).find('option:selected'));
		iAreaIndex = parseInt(iAreaIndex)-1;

		if(iAreaIndex==-1)
		{
			return;
		}

	});


	$('#submitreview').on('click',function () {

		var sBiaoti = $('input[name="biaoti"]').val();
		var iFenlei = $('select[name="fenlei"]').val();
		var iChexing = $('select[name="chexing"]').val();
		var iPinpai = $('select[name="pinpai"]').val();
		var iChengLiang = $('input[name="cheliangsl"]').val();
		var iXingche = $('input[name="xingchelc"]').val();
		var iSheng = $('input[name="sheng"]').val();
		var iShi = $('input[name="shi"]').val();
		var iXian = $('input[name="xian"]').val();
		var dGouche = $('input[name="gouchesj"]').val();
		var dNianjian = $('input[name="nianjiansj"]').val();
		var dBaoxian = $('input[name="baoxiandqsj"]').val();
		var iDipan = $('input[name="dipanh"]').val();
		var bShangpai = $('input[name="shifousp"]').val();
		var dShangpaisj = $('input[name="shangpaisj"]').val();
		var bYunying = $('input[name="shifouyysx"]').val();
		var sShouxu = $('input[name="shouxunr"]').val();
		var sYuanche = $('input[name="yuancheyt"]').val();
		var sChandi = $('input[name="chandi"]').val();
		var sYanse = $('input[name="yanse"]').val();
		var iGonglv = $('input[name="gonglv"]').val();
		var sQudong = $('input[name="qudong"]').val();
		var sPaifangbz = $('input[name="paifangbz"]').val();
		var sShuoming = $('input[name="shuoming"]').val();
		var aImgs = 'base64/img';
		var sShangpin = $('input[name="shangpinxq"]').val();
		var iYushow = $('input[name="yushoujg"]').val();
		var dShouxiao = $('input[name="youxiaoq"]').val();
		var sKanche = $('input[name="kanchedd"]').val();
		var sLianxir = $('input[name="lianxir"]').val();
		var iLianxidh = $('input[name="lianxidh"]').val();
		var bDaili = false;
		var bYongjin = $('select[name="yongjinfs"]').val();
		var iJine = $('select[name="jine"]').val();
		var sDailifs = $('select[name="dailifs"]').val();

		//提交卖车申请
		$.post('/ec/usedPublish/doSaveUsedPublish.do', {
			typeId: iFenlei,
			machName:sBiaoti,
			brandId:iPinpai,
			modelId:iChexing,
			qty:iChengLiang,
			driverMileage:iXingche,
			provinceId:iSheng,
			cityId:iShi,
			districtId:iXian,
			buyDate:dGouche,
			annualSurveyDate:dNianjian,
			insuranceDueDate:dBaoxian,
			chassisNo:iDipan,
			isLicense:bShangpai,
			licenseDate:dShangpaisj,
			isProcedure:bYunying,
			procedureContent:sShouxu,
			originalPurpose:sYuanche,
			productPlace:sChandi,
			colorId:sYanse,
			powerId:iGonglv,
			driverId:sQudong,
			emissionId:sPaifangbz,
			remark:sShuoming,
			picList:'',
			content:'',
			salePrice:'',
			validDate:'',
			address:'',
			contact:'',
			contactTel:'',
			isAgent:'',
			agentTypeId:'',
			commissionTypeId:'',
			commissionAmount:'',
			commissionRate:''
		}, function(data, textStatus, xhr) {
		


		});

	});

	

})();